package InterviewQuestions.interview2;

import com.sun.javaws.jnl.InformationDesc;

/**
 * @Author: wangliuyang
 * @Date: 2021/6/3 15:29
 * @Description:
 * 给定一个正整数M，请构造出一个长度为M的数组arr，要求
 * 对任意的i、j、k三个位置，如果i<j<k，都有arr[i] + arr[k] != 2*arr[j]
 * 返回构造出的arr
 */
public class Solution6 {
    public static int[] makeNo(int num) {
        int [] ans = new int[num];
        int index = 0;
        if (num == 2){
            return new int[]{1,2};
        }
        int[] base = makeNo(num/2 + 1);
        for(;index < ans.length ; index++) {
            ans[index] = index < base.length ? 2*base[index] + 1 : 2 * base[index - base.length];
        }
        return ans;
    }

    public static void main(String[] args) {
        int[] ints = makeNo(5);
        for (int anInt : ints) {
            System.out.println(anInt);
        }
    }
}
